package com.youhong.teethcare.decorators;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;

import com.prolificinteractive.materialcalendarview.CalendarDay;
import com.prolificinteractive.materialcalendarview.DayViewDecorator;
import com.prolificinteractive.materialcalendarview.DayViewFacade;
import com.youhong.teethcare.R;
import com.youhong.teethcare.javabeans.BrushingRecord;
import com.youhong.teethcare.utils.DBHelper;

import java.util.Calendar;
import java.util.List;

/**
 * Highlight Saturdays and Sundays with a background
 */
public class HasDataDecorator implements DayViewDecorator {

    private final Calendar calendar = Calendar.getInstance();
    private final Drawable highlightDrawable;
    private static final int color = Color.parseColor("#228BC34A");

    List<BrushingRecord> list = null;
    Context mContext;

    public HasDataDecorator(Context context) {
        this.mContext = context;
        highlightDrawable = new ColorDrawable(color);
        Calendar c = Calendar.getInstance();

        String abc = "asdasd";
    }

    int previous_month = 0;

    @Override
    public boolean shouldDecorate(CalendarDay day) {

        if (previous_month != day.getMonth()) {

            list = DBHelper.getDbHelper(mContext).queryBrushRecordGroupByYearDay(day.getYear(), 1);
            previous_month = day.getMonth();


        }


        if (list != null) {
            for (BrushingRecord record : list) {

                Calendar c = record.getStartTime();
                if (c.get(Calendar.YEAR) == day.getYear()
                        && c.get(Calendar.MONTH) == day.getMonth()
                        && c.get(Calendar.DAY_OF_MONTH) == day.getDay()) {
                    return true;
                }
            }
        }
        
        return false;
    }

    @Override
    public void decorate(DayViewFacade view) {
        view.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.bg_calender_selector));
    }

}
